package com.zhiyou.springcloud.ribbonconsumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author by zhouyanchao
 * Created on 2018/2/27.
 * Descr:
 * 改造服务消费方式，新增ConsumerService类，然后将在Controller中的逻辑迁移过去。
 * 最后，在为具体执行逻辑的函数上增加@HystrixCommand注解来指定服务降级方法
 */
@Component
public class ConsumerService {
	@Autowired
	RestTemplate restTemplate;

	public String consumer() {
		return restTemplate.getForObject("http://eureka-client/dc", String.class);
	}

	@HystrixCommand(fallbackMethod = "fallback")
	public String delay() {
		return restTemplate.getForObject("http://eureka-client/delay", String.class);
	}

/*

	public String gateway(){
			return restTemplate.getForObject()
	}
*/

	public String fallback() {
		return "fallback,延迟出错调用的方法";
	}
}
